package longcaisuyun.longcai.com.yiliubabalongcaisuyun;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.zcx.helper.http.AsyCallBack;

import longcaisuyun.longcai.com.net.GetDriverOrderCost;




public class CostActivity extends Activity implements View.OnClickListener {

    protected TextView account;
    protected TextView cartype;
    protected TextView money;
    protected TextView price;
    protected TextView jili;
    protected TextView couponprice;
    protected TextView ordercosts;
    protected TextView phone;

    TextView score;
    TextView jiliunit;
    TextView unit;
    TextView biaozhun;
    TextView ordercharge;

    private String orderid = "";

    LinearLayout account_fanhui;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cost);
        View view = getWindow().getDecorView();
        // 适配工具将视图重新排布
        MyApplication.ScaleScreenHelper.loadView((ViewGroup) view);

        orderid=getIntent().getStringExtra("orderid");

        initView();

        if(orderid!=null&&orderid.length()>0)
        {
            initData();
        }else
        {
            Toast.makeText(this,"抱歉数据出错，请重新打开",Toast.LENGTH_SHORT).show();
        }

    }


    private void initView() {

        biaozhun = (TextView) findViewById(R.id.biaozhun);
        biaozhun.setOnClickListener(this);
        account = (TextView) findViewById(R.id.account);
        cartype = (TextView) findViewById(R.id.cartype);
        money = (TextView) findViewById(R.id.money);

        ordercharge = (TextView) findViewById(R.id.ordercharge);

        unit = (TextView) findViewById(R.id.unit);
        price = (TextView) findViewById(R.id.price);
        jiliunit = (TextView) findViewById(R.id.jiliunit);

        score = (TextView) findViewById(R.id.score);

        jili = (TextView) findViewById(R.id.jili);
        couponprice = (TextView) findViewById(R.id.couponprice);
        ordercosts = (TextView) findViewById(R.id.ordercosts);
        phone = (TextView) findViewById(R.id.phone);

        findViewById(R.id.account_fanhui).setOnClickListener(this);
    }

    private void initData() {
        new GetDriverOrderCost(MyApplication.myPreferences.readUid(), orderid, new AsyCallBack<GetDriverOrderCost.Info>() {

            @Override
            public void onSuccess(String toast, int type, GetDriverOrderCost.Info info) throws Exception {
                super.onSuccess(toast, type, info);

                setView(info);
            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
                Toast.makeText(CostActivity.this, toast, Toast.LENGTH_SHORT).show();
            }
        }).execute(this, false);
    }


    private void setView(final GetDriverOrderCost.Info info) {
        if (info != null) {
            account.setText("￥ " + info.account);//实际支付
            cartype.setText("(" + info.cartype + ")");//汽车类型
            if (info.payttime.equals("1")){
                money.setText("收货时付款:现金支付"+info.money+"元");
            }else {

                money.setText("发货时付款:现金支付"+info.money+"元");
            }


          //  money.setText("收货时付款:现金支付" + info.money + "元");//收货时现金支付


            score.setText(info.account);//积分 积分等于实际支付的钱数
            ordercosts.setText(info.account + "元");//支付

            price.setText(info.price + "元");//起步价的 价格
            unit.setText("起步价(含" + info.unit + "公里)");//起步价的可用公里数

            ordercharge.setText(info.ordercosts + "元");//订单价

            jiliunit.setText("超里程费(超出" + info.jili + "公里)");//超出历程的公里数
            jili.setText(info.costs + "元");//超出功力数的价格

            couponprice.setText(info.couponprice + "元");//优惠券价格

            phone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + info.webtel));
//                    if (ActivityCompat.checkSelfPermission(CostActivity.this, android.Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
//
//                        return;
//                    }
                    startActivity(intent);

                }
            });
        }

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.biaozhun:
                Intent intent = new Intent(CostActivity.this, ShouFeiActivity.class);
                startActivity(intent);
                break;
            case R.id.account_fanhui:
                finish();
                break;

        }
    }
}
